﻿package base.loader {
	import flash.events.EventDispatcher;

	public class LoaderXML extends EventDispatcher {
		
		private var filenameXML: String;
		public var xmlNode: XML;
		public var isLoading: Boolean;
		public var isLoaded: Boolean;
		private var isAbort: Boolean;
		
		function LoaderXML(filenameXML: String): void {
			this.isLoaded = false;
			this.filenameXML = filenameXML;
		}
		
		public function readXML(): void {
			this.isLoading = true;
			this.isAbort = false;
			var urlLoaderExt: URLLoaderExt = new URLLoaderExt();
			var arrApplyFunction: Array = new Array(2);
			arrApplyFunction[0] = function(isLoaded: Boolean, strNode: String, ...args): void {
				this.isLoading = false;
				if (!this.isAbort) {
					//trace("isLoaded:" + isLoaded)
					if (isLoaded) {
						this.xmlNode = new XML(strNode);
						this.isLoaded = true;
						this.parseXML();
						this.dispatchEvent(new EventLoaderXML(EventLoaderXML.XML_LOADED));
					} else this.dispatchEvent(new EventLoaderXML(EventLoaderXML.XML_NOT_LOADED));
				}
			}
			arrApplyFunction[1] = this;
			urlLoaderExt.sendAndLoad(this.filenameXML, [], arrApplyFunction, 1, 60000, false);
		}
		
		protected function parseXML(): void {}
		
		public function abort(): void {
			this.isAbort = true;
			this.isLoading = false; 
		}
		
	}
}